package com.ruoyi.stock2.utils;

import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.J2Cache;
//j2cache 中的 CacheChannel 必须用单例 否则 并发时 堵塞 引发 null
//j2cache  由两级缓存构成 
public class J2cache {
	
	CacheChannel cache = null;
	// 单例实现
	public static J2cache getInstance(){
		return Singtonle.instance;
	}

	private static class Singtonle {
		private static J2cache instance = new J2cache();
	}
	
	
	
	public CacheChannel getCache() throws Exception{
		if(cache == null) {
			cache = J2Cache.getChannel();
		}
		return cache;
	}

	public static void main(String[] args) {
		CacheChannel cache;
		try {
			cache = J2cache.getInstance().getCache();
			int f = cache.check("default", "000001_2018-12-21");
			System.out.println(f);
			System.out.println(cache.get("default", "000001_2018-12-21").getValue());
			
			
			cache.set("default", "1", "Hello J2Cache");
		    System.out.println(cache.get("default", "1"));
		    cache.evict("default", "1");
		    System.out.println(cache.get("default", "1"));
		    
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}

}
